package com.tczs.web.service;

import com.alibaba.fastjson.JSONObject;
import com.tczs.client.bean.Command;
import com.tczs.client.bean.Where;
import com.tczs.client.service.ClientService;

public class DataService {

    public static final Long PAGE_SIZE = 10L;

    public JSONObject findData(String databaseName,String tableName,Long page){
        Command command = new Command();
        command.setCommandName("select");
        command.setDatabaseName(databaseName);
        command.setTableName(tableName);
        Where where = new Where();
        where.START((page-1)*PAGE_SIZE+1).LIMIT(PAGE_SIZE);
        command.setWhere(where);
        String send = ClientService.send(null, command);
        return JSONObject.parseObject(send);
    }

    public JSONObject selectCount(String databaseName,String tableName){
        Command command = new Command();
        command.setCommandName("selectCount");
        command.setDatabaseName(databaseName);
        command.setTableName(tableName);
        String send = ClientService.send(null, command);
        JSONObject jsonObject = JSONObject.parseObject(send);
        return jsonObject;
    }
}
